package com.xinfu.newproject.presenter;

import android.util.Log;

import com.xinfu.newproject.bean.login.LoginBean;
import com.xinfu.newproject.bean.login.RegisterBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.login.RegisterModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

import static com.xinfu.newproject.activity.LoginActivity.FRAGMENT_ACTIVITY;

public class RegisterPresenter {
    private IView.IRegisterView mIRegisterView;

    RegisterModel mRegisterModel;
    //  private LoginModel mPhoneModel;

    public RegisterPresenter(IView.IRegisterView iRegisterView) {
        this.mIRegisterView = iRegisterView;
        mRegisterModel = new RegisterModel();
    }

    /**
     * 登录
     */
    public void register() {
      /*  Map<String, String> paraMap =new HashMap<>();
        paraMap.put("userName",mIPhoneView.getUserName());
        paraMap.put("passWord",mIPhoneView.getPassWord());*/
        mIRegisterView.showProgress();

        RegisterBody registerBody = new RegisterBody(mIRegisterView.getUserName(), mIRegisterView.getSMSCode(), mIRegisterView.getPassword());

        mRegisterModel.register(registerBody, new MyCallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean LoginBean) {
                mIRegisterView.hideProgress();
                if (LoginBean.getCode() == 200) {
                    if (LoginBean.isSuccess()) {
                        mIRegisterView.toOtherActivity(FRAGMENT_ACTIVITY, LoginBean.getResult());
                    } else {
                        mIRegisterView.showToast(LoginBean.getMessage());
                    }

                }
                mIRegisterView.showToast(LoginBean.getMessage());
                Log.i("testPhone", "success=" + LoginBean.isSuccess() + "code=" + LoginBean.getCode() + "message=" + LoginBean.getMessage() + "result=" + LoginBean.getResult());
            }

            @Override
            public void onError(String header, String message) {
                mIRegisterView.hideProgress();
                mIRegisterView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIRegisterView.closeDispose(disposable);
            }
        });


    }


//    private Map<String, String> createParaMap() {
//        Map<String, String> paraMap = new HashMap<>();
//        paraMap.put("userName", mIRegisterView.getUserName());
//        return paraMap;
//    }

}
